import request from '@/config/axios'

// 单据 VO
export interface MaterialDemandVO {
    id: number
    type: string // 类型（1-项目，3办公室，2零星，4销售，5采购）
    belongingProject: String // 归属项目id
    documentNumber: String // 单据编号
    auditStatus: String // 审核状态（0-待审核，1-审核通过，2-审核不通过）
    processInstanceId: number // 流程实例id
    projectOrders: []
    documentDate: Date // 单据日期
}

// 单据 API
export const MaterialDemandApi = {

    // 提交审核
     submitReceivable : async (id: number) => {
        return await request.put({ url: `/purchase/material-demand/submit?id=${id}` })
    },
    // 查询单据分页
    getMaterialDemandPage: async (params: any) => {
        return await request.get({url: `/purchase/material-demand/page`, params})
    },

    // 查询单据详情
    getMaterialDemand: async (id: number) => {
        return await request.get({url: `/purchase/material-demand/get?id=` + id})
    },

    // 新增单据
    createMaterialDemand: async (data: MaterialDemandVO) => {
        return await request.post({url: `/purchase/material-demand/create`, data})
    },

    // 修改单据
    updateMaterialDemand: async (data: MaterialDemandVO) => {
        return await request.put({url: `/purchase/material-demand/update`, data})
    },

    // 修改单据
    updateByIdMaterialDemand: async (data: MaterialDemandVO) => {
        return await request.put({url: `/purchase/material-demand/updateById`, data})
    },

    // 删除单据
    deleteMaterialDemand: async (id: number) => {
        return await request.delete({url: `/purchase/material-demand/delete?id=` + id})
    },

    // 导出单据 Excel
    exportMaterialDemand: async (params) => {
        return await request.download({url: `/purchase/material-demand/export-excel`, params})
    },

// ==================== 子表（办公申请单） ====================

    // 获得办公申请单列表
    getOfficeOrderListByDocumentNumber: async (documentNumber) => {
        return await request.get({url: `/purchase/material-demand/office-order/list-by-document-number?documentNumber=` + documentNumber})
    },

// ==================== 子表（项目物资申请单） ====================

    // 获得项目物资申请单列表
    getProjectOrderListByDocumentNumber: async (documentNumber) => {
        return await request.get({url: `/purchase/material-demand/project-order/list-by-document-number?documentNumber=` + documentNumber})
    },
}
